#include "propertytreedockwidget.h"
#include <QVBoxLayout>
#include "qsignalslotcenter.h"

namespace PublicGui
{
PropertyTreeDock::PropertyTreeDock(QWidget * parent):QDockWidget(parent)
	{
		QWidget* pwidget = new QWidget();
		QVBoxLayout* verticalLayout = new QVBoxLayout(pwidget);
		verticalLayout->setSpacing(6);
		verticalLayout->setMargin(11);
		verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
		verticalLayout->setContentsMargins(0, 0, 0, 0);
		_propertyTree=new PropertyTreeWidget(NULL,pwidget);
		verticalLayout->addWidget(_propertyTree);
		connect(&QSignalSlotCenter::QSignalSlotCenter::GetInstance(),
			SIGNAL(signalSelecteActorObjectChanged(QVector<CoreBase::ActorBase*>)),this,
			SLOT(slotSelecteActorObjectChanged(QVector<CoreBase::ActorBase*>)));
		connect(&QSignalSlotCenter::QSignalSlotCenter::GetInstance(),
			SIGNAL(signalRunPropertyEditCommand(QVector<CoreBase::ActorBase*>,int)),this,
			SLOT(slotRunPropertyEditCommand(QVector<CoreBase::ActorBase*>,int)));
		setWidget(pwidget);
	}

	PropertyTreeDock::~PropertyTreeDock()
	{}

	void PropertyTreeDock::slotSelecteActorObjectChanged(QVector<CoreBase::ActorBase*> objects)
	{
		if(objects.size()!=1 || isHidden())
		{
			_propertyTree->setWidgetActor(NULL);
			return;
		}
		if(objects.at(0) == _propertyTree->getCurrentActor())
			return;
		_propertyTree->setWidgetActor(objects.at(0));
	}

	void PropertyTreeDock::slotRunPropertyEditCommand(QVector<CoreBase::ActorBase*> vector,int action)
	{
		if(vector.size() == 1 && vector.at(0) == _propertyTree->getCurrentActor() && action == ACTION_UNDO_EVENT
			&& !isHidden())
			_propertyTree->setWidgetActor(vector.at(0));
	}
}